package com.axend.aerosense.room.ui.provider;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.databinding.DataBindingUtil;

import com.axend.aerosense.room.ui.adapter.PersonProviderMultiAdapter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.axend.aerosense.common.bean.PersonSelectItemBean;
import com.axend.aerosense.room.R;
import com.axend.aerosense.room.databinding.RoomPersonItemBinding;

import org.jetbrains.annotations.NotNull;

public class PersonProvider extends BaseItemProvider<PersonSelectItemBean> {
    private RoomPersonItemBinding contractItemBinding;
    private boolean selectMode;

    public PersonProvider(Boolean selectMode) {
        this.selectMode = selectMode;
    }

    @Override
    public int getItemViewType() {
        return PersonProviderMultiAdapter.TYPE_COMMON;
    }

    @Override
    public int getLayoutId() {
        return R.layout.room_person_item;
    }

    @Override
    public void convert(@NotNull BaseViewHolder baseViewHolder, PersonSelectItemBean bean) {
        // 获取 Binding
        contractItemBinding = baseViewHolder.getBinding();
        if (contractItemBinding != null) {
            contractItemBinding.setViewModel(bean);
            contractItemBinding.executePendingBindings();

            if(!TextUtils.isEmpty(bean.getEmergencyImg())){
                ImageView imageView = baseViewHolder.findView(R.id.room_user_head);
                Glide.with(imageView.getContext()).load(bean.getEmergencyImg()).placeholder(R.mipmap.common_img_default_head)
                        .skipMemoryCache(true)
                        .diskCacheStrategy( DiskCacheStrategy.NONE ).circleCrop().into(imageView);
            }

        }
    }

    @Override
    public void onViewHolderCreated(@NotNull BaseViewHolder viewHolder, int viewType) {
        super.onViewHolderCreated(viewHolder, viewType);
        contractItemBinding = DataBindingUtil.bind(viewHolder.itemView);
        if(selectMode){
            contractItemBinding.roomCheck.setVisibility(View.VISIBLE);
        }else{
            contractItemBinding.roomCheck.setVisibility(View.GONE);
        }

    }
}
